package com.cy.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.time.LocalDateTime;

public class TimeInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        LocalDateTime time = LocalDateTime.now();
        int hour = time.getHour();
        if (hour<=12||hour>23)
            throw new RuntimeException("请在指定时间访问");
        return HandlerInterceptor.super.preHandle(request, response, handler);
    }
}
